package com.neusoft.core.util.jwt;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

public class JwtTestCase {
	@Test
	public void test1() {
		// 校验过期----------------------------------------------------------------------------------------------------
		String token = null;
		Map<String, Object> payload = new HashMap<String, Object>();
		Date date = new Date();
		payload.put("uid", "291969452");// 用户id
		payload.put("iat", date.getTime());// 生成时间
		payload.put("ext", date.getTime());// 过期时间就是当前
		token = Jwt.createToken(payload);
		System.out.println("新生成的token是：" + token + "\n马上将该token进行校验");
		Map<String, Object> resultMap = Jwt.validToken(token);
		System.out.println("校验结果是:"
				+ getResult((String) resultMap.get("state")));
	}

	private String getResult(String state) {
		switch (TokenState.getTokenState(state)) {
		case VALID:
			// To do somethings
			state = "有效token";
			break;
		case EXPIRED:
			state = "过期token";
			break;
		case INVALID:
			state = "无效的token";
			break;
		}
		return state;
	}
}
